import { get } from '@/utils/http'
import { NEWS_FETCHNEWSLIST } from '@/store/types/newsType'

// 新闻
export default {
  // 强制命名空间，这样它就会让 getters/mutations/actions在调用时都有命名空间
  namespaced: true,
  state: {
    newslist: []
  },
  getters: {
    lists: state => state.newslist
  },
  mutations: {
    addNewslist(state, data) {
      state.newslist = data
    },
    addNum(state, payload = 1) {
      console.log('news模块', payload)
    }
  },
  actions: {
    async [NEWS_FETCHNEWSLIST]({ commit }, payload) {
      let ret = await get('/api/news')
      commit('addNewslist', ret.data)
    }
  }
}
